#!/bin/bash
set -e

while getopts  "s:w:c:p:g:" opts
do
	case  $opts  in
	s)
		sample_name=$OPTARG
		;;
	w)
		window=$OPTARG
		;;
	c)
		c_const=$OPTARG
		;;
	g)
        ref_genome=$OPTARG
        ;;
	p)
        out_prefix=$OPTARG
        ;;
	\?)
		echo `basename $0` "[-s sample_name] [-w window_size] [-g ref_genome_file] <sample.bam> <control.bam>"
		exit 1
		;;
	esac
done
shift $(($OPTIND - 1))

if [ -z "$2" ]; then
	echo `basename $0` '[-s sample_name] [-w window_size] [-g ref_genome_file] <sample.bam> <control.bam>'
	exit 1
fi

#-----------------------------------------------
#-----------------------------------------------
. /mnt/ilustre/app/medical/tools/.var #---------
#-----------------------------------------------
#-----------------------------------------------
log=.log
if [ ! -e "$log" ]; then
	:> $log
fi

if [ -z $out_prefix ]; then
	out_prefix=1
fi

if [ -z "$window" ]; then
	window=200000
fi

# if [ -z "$ref_genome" ]; then
	# ref_genome=ref_genome
# fi

datee=`date +h%Hm%Ms%S_m%md%d_%y`
dir_name=$sample_name$datee
mkdir $dir_name
cd $dir_name

cutadp.sh $1 $2 2>>log

align2bam -s $sample_name 1.1.cut.fastq 1.2.cut.fastq 2>>log

hmmcopy0727.sh -w $win_size 1.sort.bam $data_path/cnv_ref/2.sort.bam 2>>log

summ_sc_gatk.sh 1.sort.bam $data_path/intervals/1/cnv_sc/b37.rand.site.bed 2>>log

